package br.com.felix.fwt.ui.validation;

import java.util.ArrayList;
import java.util.List;

import br.com.felix.fwt.ui.BaseComponent;

public class SameValueValidator extends Validator{

	public SameValueValidator(BaseComponent... components) {
		super(components);
	}

	
	
	@Override
	public List<ValidationError> isValid() {
		List<ValidationError> lst = new ArrayList<ValidationError>();
		BaseComponent[] components = getComponents();
		BaseComponent c;
		String value = components[0].getValue();
		String otherComponentValue;
		for (int i=1; i< components.length; i++){
			c = components[i];
			otherComponentValue = c.getValue();
			if (!value.equals(otherComponentValue)){
				ValidationError ve = new ValidationError("SameValueError");
				ve.setReferences((Object[])components);
				lst.add(ve);
			}
		}
		return lst;
	}

}
